#ifndef CRACK_H
#define CRACK_H

#include "DES.h"

/* Maximum length of plaintext/ciphertext supported (in bytes) */
#define MAX_LENGTH 10000

/* Global storing number of plaintext/ciphertext pairs */
int BLOCKS;

/* Globals storing 32-bit data within the DES */
uchar L0[MAX_LENGTH/8][4];
uchar R0[MAX_LENGTH/8][4];
uchar L1[MAX_LENGTH/8][4];
uchar R1[MAX_LENGTH/8][4];
uchar R2[MAX_LENGTH/8][4];
uchar L2[MAX_LENGTH/8][4];
/*used for InverseKeyCompression*/
const uint8_t InvKeyComp[48];
const uint8_t InverseKeyPermuteMap[56];

 
const uint8_t mapKtoK1[48];
const uint8_t mapKtoK2[48];
const uint8_t map_K1toK2[48];

/* Globals used in crack_K1 and crack_K2 for storing keys matched */
uchar k1_match[10][6];
uchar k2_match[10][6];
/* Cracks the 48-bit key K1 of the first round from given pairs */
int crack_K1();
/* Cracks the 48-bit key K2 of the second round from given pairs */
int crack_K2();
/* Checks if a candidate key is correct for a given left-right pair */
int check_key(uchar* Li, uchar* Ri, uchar* Kj, uchar* Rj);

/* Performs the Feistel Cipher */
void feistel(uchar* Ri, uchar* Kj, uchar* f_out);

 

#endif
